<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function cleartbox()
{	
	document.getElementById("Sea_Lab").innerHTML="";
}
</script>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Lab_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{ 
document.lab.LabId.value=val;
document.getElementById("List").innerHTML="";
}
</script>
<script type="text/javascript">
function getRes(hin)
{
var xmlhttp;    
if (hin=="")
  {
  document.getElementById("Sea_Lab").innerHTML='<font class="err"><img src="../images/alert.jpg" width="12" height="12"/> Please enter the Lab Id!</font>';
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("Sea_Lab").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","search.php?q="+hin,true);
xmlhttp.send();
}
</script>

</head>
<body>
<?php
require_once '../Login/databaseconnection.php';
if(!loggedin())
{
require_once '../index.php';
}
else
{	
 $action=$_GET['action'];
   if($_GET['action']=="lab")
   {
   $Lab_Type=$_GET['lt'];
}
 if($_GET['action']=="school")
   {   
    $Lab_Id=$_GET['l'];
   $S_Id=$_GET['s'];   
}
if($_GET['action']=="accountnumber")
   {  
  $Account_Number=$_GET['an'];
   }
   if($_GET['action']=="phonenumber")
   {  
  $Phone_Number=$_GET['pn'];
    }
	if($_GET['action']=="school")
   {
if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   if($S_Id==$Own_School_Id)
   {
   $Exc_que="SELECT * FROM lab Where Lab_Id='$Lab_Id' AND School_Id='$Own_School_Id'";
	$result=mysql_query("SELECT * FROM lab Where Lab_Id='$Lab_Id' AND School_Id='$Own_School_Id'");
if(mysql_num_rows($result)==0)
   {
   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
   }
    else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM lab Where Lab_Id='$Lab_Id' AND School_Id='$S_Id'";
 $result=mysql_query("SELECT * FROM lab Where Lab_Id='$Lab_Id' AND School_Id='$S_Id'");
if(mysql_num_rows($result)==0)
   {
$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
   }
   if($_GET['action']=="lab")
   {
if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $Exc_que="SELECT * FROM lab Where Lab_Type='$Lab_Type' AND School_Id='$Own_School_Id'";
	$result=mysql_query("SELECT * FROM lab Where Lab_Type='$Lab_Type' AND School_Id='$Own_School_Id'");
if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM lab Where Lab_Type='$Lab_Type'";
 $result=mysql_query("SELECT * FROM lab Where Lab_Type='$Lab_Type'");
if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
   }
   if($_GET['action']=="accountnumber")
   {
if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   	$che_sch=mysql_query("SELECT * FROM lab Where Account_Number='$Account_Number'");
	while($che_school=mysql_fetch_array($che_sch))
	{
	$Acc_School_Id=$che_school['School_Id'];
	if($Own_School_Id==$Acc_School_Id)
	{
	$Exc_que="SELECT * FROM lab Where Account_Number='$Account_Number' AND School_Id='$Own_School_Id'";
	$result=mysql_query("SELECT * FROM lab Where Account_Number='$Account_Number' AND School_Id='$Own_School_Id'");
if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
	}
	}
	if(mysql_num_rows($che_sch)==0)
   {
    $_SESSION['errornorow']="Very sorry there is no result!";
   }
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM lab Where Account_Number='$Account_Number'";
 $result=mysql_query("SELECT * FROM lab Where Account_Number='$Account_Number'");
if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
   }
   if($_GET['action']=="phonenumber")
   {
if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   	$che_sch=mysql_query("SELECT * FROM lab Where Tp_Number='$Phone_Number'");
	while($che_school=mysql_fetch_array($che_sch))
	{
	$Acc_School_Id=$che_school['School_Id'];
	if($Own_School_Id==$Acc_School_Id)
	{
	$Exc_que="SELECT * FROM lab Where Tp_Number='$Phone_Number' AND School_Id='$Own_School_Id'";
	$result=mysql_query("SELECT * FROM lab Where Tp_Number='$Phone_Number' AND School_Id='$Own_School_Id'");
if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
	}
		}
	if(mysql_num_rows($che_sch)==0)
   {
    $_SESSION['errornorow']="Very sorry there is no result!";
   }
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
 $result=mysql_query("SELECT * FROM lab Where Tp_Number='$Phone_Number'");
 $Exc_que="SELECT * FROM lab Where Tp_Number='$Phone_Number'";
if(mysql_num_rows($result)==0)
   {

	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
   }
?>
<?php
include_once "../header2.php";
?><?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<div id="lefttable">
<table width="530" border="0" class="tablefontv">
<tr><td width="47" height="43" class="err">
<?php
if(isset($_SESSION['errornotallo']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornotallo'];
		unset($_SESSION['errornotallo']);
	}
	if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
?>
</td></tr></tabe>
  <table width="530" border="0" class="tablefontv">
  <tr><form name="lab">
  <td width="47" height="43">&nbsp;</td>
      <td width="131">Lab's Id:</td>
      <td width="149">
	  <?php
	    $Lab_Id=$Lab_Id;
	 	  echo "<input type='text' id='LabId' name='LabId' onKeyUp='showHint(this.value)' value='$Lab_Id' onClick='cleartbox()' size='25'/>";
	  ?>
	  </td>
      <td width="33"><input type="button" class="searchid" onClick="getRes(LabId.value)"></td>
      <td width="148">
     </td></form></tr>
   <tr>
  <td>
  </td>
  <td>
  </td><td>
 <div class="suggestionListPro" id="List"></div> </td>
 <td>
 </td>
 <td></td>
  </tr></table>
  <br/>
<div id="Sea_Lab">
<?php 

 if($result)
	{
	if(mysql_num_rows($result)>1)
	   {
	   $colu="";
	   $sql=mysql_query("SHOW COLUMNS FROM lab");
if(mysql_num_rows($result)>11)
{
	   echo '<div style =" width:980px; height:300px; overflow-Y:scroll; ">';
}
      echo '<table border="1" class="tablefontv">';
	  echo "<tr bgcolor='#6AB5FF'>";
	while($rowc=mysql_fetch_row($sql))
  {
  if(empty($colu))
  {
  $colu=$rowc[0];
  }
  else
  {
   $colu=$colu.",".$rowc[0];
  }
  if($rowc[0]=="School_Id")
  {
    echo "<td>School Name</td>";
  }
  else
  {
  echo "<td>".$rowc[0]."</td>";
  }
  }
  echo "</tr>";
 $columns=explode(",",$colu);
        while($row=mysql_fetch_array($result))
  {
 echo "<tr bgcolor='#999999'>";
  for($cv=0;$cv<mysql_num_rows($sql);$cv++)
	{
	 $col_name=$columns[$cv];
	 if($col_name=="School_Id")
	 {
	  $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$row[$col_name]."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
$Name=$rs['Name'];
}
 echo "<td>".$Name."</td>";
	 }
	 else
	 {
	    echo "<td>".$row[$col_name]."</td>";
		}
	}
	  echo '</tr>';
	}
	echo '</table>';
if(mysql_num_rows($result)>11)
{
	echo '</div>';
}
	   }
	   if(mysql_num_rows($result)==1)
	   {
	     $colu="";
	   $sql=mysql_query("SHOW COLUMNS FROM lab");
	while($rowc=mysql_fetch_row($sql))
  {
  if(empty($colu))
  {
  $colu=$rowc[0];
  }
  else
  {
   $colu=$colu.",".$rowc[0];
  }
  }
 $columns=explode(",",$colu);
	  echo '<table width="458" border="0" class="tablefontv">';
 while($row=mysql_fetch_array($result))
 {
for($cv=0;$cv<mysql_num_rows($sql);$cv++)
	{
	 echo '<tr align="center">';
	 $col_name=$columns[$cv];
	echo '<th width="200" height="30" scope="row" bgcolor="#6AB5FF">';
	if($col_name=="School_Id")
  {
    echo "School Name:";
  }
  else
  {
		echo str_replace("_"," ",$col_name).":";
		}
		echo '</th><td width="144" bgcolor="#999999">';
			if($col_name=="School_Id")
  {
    $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$row[$col_name]."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
$Name=$rs['Name'];
}
echo $Name;
  }
  else
  {
		echo $row[$col_name];
		}
		echo '</td>';
		 echo '</tr>'; 
		}
 }
  echo "</table>";
	   }
	   }
if($result)
{
$Exc_quer=str_replace("'","@",$Exc_que);
echo "<form action='../exportreport.php' method='post'><input type='submit' name='ToExcel' class='print' value=''/><input type='hidden' value='$Exc_quer' name='query'/><input type='hidden' value='lab' name='Exc_table_name'/></form>";
}
   ?>
</div>
</div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">LABS</h2>
            </div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
</div>
</div>
<?php

}
?>
</body>
</html>